package com.cyj.minio.controller.nacos;

import com.cyj.minio.common.constant.model.Response;
import com.cyj.minio.common.constant.model.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: Nacos配置中心控制器
 * @BelongsProject: SpringBoot-MinIO
 * @BelongsPackage: com.cyj.minio.controller.nacos
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-13 16:28
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@RefreshScope
@RestController
@RequestMapping(value = "/pc/nacos", name = "Nacos配置中心控制器")
@Api(value = "nacosConfig", tags = "Nacos 配置中心进行配置信息获取测试 controller")
public class NacosConfigController {

    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    @Value("${spring.datasource.driver-class-name}")
    private String driverClassName;

    /**
     * 手动刷新配置信息
     *
     * @return java.lang.String
     * @author ChenYongJia
     * @date 17:24 2021/9/13
     */
    @RefreshScope
    @ApiOperation(value = "测试调用从 nacos 获取的配置信息", httpMethod = "GET")
    @RequestMapping(value = "/getS")
    public Response getConfig() {
        Map<String, Object> map = new HashMap<>(16);
        log.info(dbUrl);
        log.info(username);
        log.info(password);
        log.info(driverClassName);
        map.put("dbUrl", dbUrl);
        map.put("username", username);
        map.put("password", password);
        map.put("driverClassName", driverClassName);
        return ResponseUtil.success(map);
    }

}
